import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-09-09
 * Time: 15:49
 */
public class Test {
    // https://leetcode.cn/problems/merge-sorted-array/
    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int i = m - 1;
        int j = n - 1;
        int k = m + n - 1;
        while (i >= 0 && j >= 0) {
            if (nums2[j] >= nums1[i]) {
                nums1[k] = nums2[j];
                j--;
                k--;
            } else {
                nums1[k] = nums1[i];
                i--;
                k--;
            }
        }
        while (i >= 0) {
            nums1[k] = nums1[i];
            i--;
            k--;
        }
        while (j >= 0) {
            nums1[k] = nums2[j];
            j--;
            k--;
        }
    }

    public static void main(String[] args) {
        int[] arr1 = {1,2,3,0,0,0};
        int[] arr2 = {2,5,6};
        merge(arr1, 3, arr2, 3);
        System.out.println(Arrays.toString(arr1));
    }



    // https://leetcode.cn/problems/remove-duplicates-from-sorted-array/
    public static int removeDuplicates(int[] nums) {
        int len = nums.length;
        while (isRepeat(nums, len) != -1) {
            for (int i = isRepeat(nums, len); i < len-1; i++) {
                nums[i] = nums[i+1];
            }
            len--;
        }
        return len;
    }
    public static int isRepeat(int[] arr, int len) {
        for (int i = 0; i < len-1; i++) {
            if (arr[i] == arr[i+1]) {
                return i;
            }
        }
        return -1;
    }

    public static void main6(String[] args) {
        int[] arr = {1,1,2};
        int len = removeDuplicates(arr);
        for (int i = 0; i < len; i++) {
            System.out.println(arr[i]);
        }
    }

    // https://leetcode.cn/problems/remove-element/
    public static int indexOf(int[] arr, int toFind, int len) {
        for (int i = 0; i < len; i++) {
            if (arr[i] == toFind) {
                return i;
            }
        }
        return -1;
    }
    public static int removeElement(int[] nums, int val) {
        int len = nums.length;
        while (indexOf(nums, val, len) != -1) {
            for (int i = indexOf(nums, val, len); i < len-1; i++) {
                nums[i] = nums[i+1];
            }
            len--;
        }
        return len;
    }

    public static void main4(String[] args) {
        int[] arr = {0,1,2,2,3,0,4,2};
        int len = removeElement(arr, 2);
        for (int i = 0; i < len; i++) {
            System.out.println(arr[i]);
        }
    }

    public static void main3(String[] args) {
        Random arr = new Random();
        int n = arr.nextInt(100);
        System.out.println(n);
        Scanner scan = new Scanner(System.in);
        while(scan.hasNextInt()) {
            int a = scan.nextInt();
            if(a == n) {
                break;
            }
        }
    }
    public static void main2(String[] args) {
        int i = 1;
        while(i<=100) {
            if(i%3 == 0 && i%5 == 0) {
                System.out.println(i);
            }
            i++;
        }
    }
    public static void main1(String[] args) {
        int i = 1;
        int ret = 1;
        int arr = 0;
        while(i <= 5) {
            ret *= i;
            i++;
            System.out.println(ret);
            arr += ret;
            System.out.println(arr);
            System.out.println(" ");
        }
    }
}
